<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<style type="text/css">
.table td, .table th{
    text-align: center;
}
.collect_txt{
    margin-left: 10px;
    color: #ccc;
}
.row .right-price{
	text-align: right;
	padding-right:20px;
}
</style>

<body class="pear-container">
	
<script src="__JS__/highcharts-9.1.2.js"></script>
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
           <header class="panel-heading">{$year}年销售统计表</a></header>
            <div class="panel-body">
                <div class="col-lg-12">
                    <p class="text-muted">统计年份</p>
                    <div class="btn-group">
                      <button class="btn btn-white" type="button">{$year}年</button>
                      <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button"><span class="caret"></span></button>
                      <ul role="menu" class="dropdown-menu">
                          {for start="$old_year" end="date('Y')+1"}
                          <li><a href="{:U('Collect/sale',['year'=>$i])}">{$i}年</a></li>
                          {/for}
                      </ul>
                    </div>
                    {if $month gt 0}
                    <a class="btn btn-info" href="{:U('Collect/sale',['year'=>$year])}"><i class="icon-reply"></i> 返回年统计</a>
                    {else/}
                    <span class="collect_txt">选择年份可切换年度报表，点击月份可查看该月报表</span>
                    {/if}
                    <p class="text-muted"></p>
                </div>
                {if $month == 0}
                <div class="col-lg-12">
                  <section id="unseen">
                    <table class="table table-bordered table-striped table-condensed">
                      <thead>
                      <tr>
                          <th width="9%">名称</th>
                          {for start="1" end="$length+1"}
                          <th width="7%"><a href="{:U('Collect/sale',['year'=>$year,'month'=>$i])}">{$i}月</a></th>
                          {/for}
                          <th width="7%">汇总</th>
                      </tr>
                      </thead>
                      <tbody>
						  <tr>
						      <td>新增客户</td>
						      {php}
						      $a=0;
						      for($i=1;$i<=$length;$i++){
						        echo '<td>'.$T[$i]['dow'].' 人</td>';
						        $a+=$T[$i]['dow'];
						      }
						      echo '<td>'.$a.' 人</td>';
						      {/php}
						  </tr>
                      <tr>
                          <td>下单客户</td>
                          {php}
                          $a=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.$T[$i]['cus'].' 人</td>';
                            $a+=$T[$i]['cus'];
                          }
                          echo '<td>'.$a.' 人</td>';
                          {/php}
                      </tr>
                      <tr>
                          <td>采购单量</td>
                          {php}
                          $a=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.$T[$i]['count'].' 单</td>';
                            $a+=$T[$i]['count'];
                          }
                          echo '<td>'.$a.' 单</td>';
                          {/php}
                      </tr>
                      <tr>
                          <td>大货匹数</td>
                          {php}
                          $a=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.$T[$i]['roll'].' 匹</td>';
                            $a+=$T[$i]['roll'];
                          }
                          echo '<td>'.$a.' 匹</td>';
                          {/php}
                      </tr>
                      <tr>
                          <td>销售额</td>
                          {php}
                          $year_total=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.price_one($T[$i]['total']).'</td>';
                            $year_total+=$T[$i]['total'];
                          }
                          echo '<td>'.price_one($year_total).'</td>';
                          {/php}
                      </tr>
                      <tr>
                          <td>进货成本</td>
                          {php}
                          $a=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.price_one($T[$i]['cost']).'</td>';
                            $a+=$T[$i]['cost'];
                          }
                          echo '<td>'.price_one($a).'</td>';
                          {/php}
                      </tr>
					  <tr>
					      <td>毛利润</td>
					      {php}
					      $year_profit=0;
					      for($i=1;$i<=$length;$i++){
					        echo '<td><a href="'.U('Bill/index',['y'=>$year,'m'=>$i,'type'=>1]).'">'.price_one($T[$i]['g_profit']).'</a></td>';
					        $year_profit+=$T[$i]['g_profit'];
					      }
					      echo '<td>'.price_one($year_profit).'</td>';
					      {/php}
					  </tr>
					  <tr>
					      <td>开销支出</td>
					      {php}
					      $year_invest=0;
					      for($i=1;$i<=$length;$i++){
					        echo '<td><a href="'.U('Bill/index',['y'=>$year,'m'=>$i,'type'=>0]).'">'.price_one($T[$i]['invest']).'</a></td>';
					        $year_invest+=$T[$i]['invest'];
					      }
					      echo '<td>'.price_one($year_invest).'</td>';
					      {/php}
					  </tr>
                      <tr>
                          <td>净利润</td>
                          {php}
                          $year_profit=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>'.price_one($T[$i]['n_profit']).'</td>';
                            $year_profit+=$T[$i]['n_profit'];
                          }
                          echo '<td>'.price_one($year_profit).'</td>';
                          {/php}
                      </tr>
                      <tr>
                          <td>毛利率</td>
                          {php}
                          $a=0;
                          for($i=1;$i<=$length;$i++){
                            echo '<td>';
							if($T[$i]['total']>0){
								echo price_one($T[$i]['g_profit']/$T[$i]['total']*100);
							}else{
								echo 0;
							}
							echo ' %</td>';
                          }
						  echo '<td>';
						  if($year_profit==0 && $year_total==0){
							  echo 0;
						  }else{
							  echo price_one($year_profit/$year_total*100);
						  }
						  echo ' %</td>';
                          {/php}
                      </tr>
                      </tbody>
                  </table>
                  </section>
                </div>
                {/if}
                <div id="collect1"></div>
                <div id="collect2"></div>
                {if $month gt 0}
                <div class="col-lg-12">
                  <section id="unseen">
                    <table class="table table-bordered table-striped table-condensed">
                      <thead>
                      <tr>
                          <th width="20%">日期</th>
                          <th width="10%">销售额</th>
						  <th width="10%">新增客户</th>
                          <th width="10%">大货数</th>
                          <th width="10%">订单量</th>
                          <th width="10%">进货成本</th>
						  <th width="10%">当日开销</th>
                          <th width="20%">净利润</th>
                      </tr>
                      </thead>
                      <tbody>
                      {volist name="T" id="v"}
                      <tr>
                          <td><a href="{:U('Deal/index',['year'=>$year,'month'=>$month,'day'=>$key,'cost'=>1])}" target="_blank">{$year}年{$month}月{$key}日</a></td>
                          <td class="right-price">{$v.total|price_one}</td>
                          <td>{$v.dow} 人</td>
						  <td>{$v.roll} 匹</td>
                          <td>{$v.count} 单</td>
                          <td class="right-price">{$v.cost|price_one}</td>
						  <td class="right-price">{$v.invest|price_one}</td>
                          <td class="right-price">{$v.n_profit|price_one}</td>
                      </tr>
                      {/volist}
                      </tbody>
                  </table>
                  </section>
                </div>
                {/if}
            </div>
        </section>
    </div>
</div>
<script type="text/javascript">
var chart = Highcharts.chart('collect1', {
    chart: {
        type: 'areaspline'
    },
    title: {
        {php}
        if($month<=0){
            echo "text: '".$year."年度销售情况表'";
        }else{
            echo "text: '".$year."年".$month."月销售情况表'";
        }
        {/php}
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        verticalAlign: 'top',
        x: 150,
        y: 100,
        floating: true,
        borderWidth: 1,
        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
    },
    xAxis: {
        {php}
        if($month<=0){
            echo "categories: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],";
        }else{
            $str="categories: [";
            for($i=1;$i<=$length;$i++){
                $str.= $i.',';
            }
            echo substr($str,0,-1).'],';
        }
        {/php}
    },
    yAxis: {
        title: {
            text: ''
        }
    },
    tooltip: {
        shared: true,
        valueSuffix: '元'
    },
    plotOptions: {
        areaspline: {
            fillOpacity: 0.7
        }
    },
    series: [{
        name: '销售额',
        data: [{$total}]
    },{
        name: '净利润',
        data: [{$n_profit}]
    }
    ]
});

var chart = Highcharts.chart('collect2',{
    chart: {
        type: 'column'
    },
    title: {
        {php}
        if($month<=0){
            echo "text: '".$year."年度下单情况表'";
        }else{
            echo "text: '".$year."年".$month."月下单情况表'";
        }
        {/php}
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        {php}
        if($month<=0){
            echo "categories: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],";
        }else{
            $str="categories: [";
            for($i=1;$i<=$length;$i++){
                $str.= $i.',';
            }
            echo substr($str,0,-1).'],';
        }
        {/php}
        crosshair: true
    },
    yAxis: {
        min: 0,
        title: {
            text: '下单情况'
        }
    },
    tooltip: {
        // head + 每个 point + footer 拼接成完整的 table
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
        '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    plotOptions: {
        column: {
            borderWidth: 0
        }
    },
    series: [{
        name: '新增客户',
        data: [{$dow}]
    }, {
        name: '下单客户',
        data: [{$cus}]
    }, {
        name: '采购单量',
        data: [{$count}]
    }, {
        name: '采购大货',
        data: [{$roll}]
    }]
});
</script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
